home *** CD-ROM | disk | FTP | other *** search
/ PC Basics 53 / PC Basics Issue 53.iso / Software / Internet / Invboard.exe / PC Basics 53 / Invboard / upload / sources / Profile.php < prev    next >
Encoding:
PHP Script  |  2002-06-12  |  9.5 KB  |  301 lines

  1. <?php
  2.  
  3. /*
  4. +--------------------------------------------------------------------------
  5. |   IBFORUMS v1
  6. |   ========================================
  7. |   by Matthew Mecham and David Baxter
  8. |   (c) 2001,2002 IBForums
  9. |   http://www.ibforums.com
  10. |   ========================================
  11. |   Web: http://www.ibforums.com
  12. |   Email: phpboards@ibforums.com
  13. |   Licence Info: phpib-licence@ibforums.com
  14. +---------------------------------------------------------------------------
  15. |
  16. |   > User Profile functions
  17. |   > Module written by Matt Mecham
  18. |   > Date started: 28th February 2002
  19. |
  20. |    > Module Version Number: 1.0.0
  21. +--------------------------------------------------------------------------
  22. */
  23.  
  24.  
  25. $idx = new Profile;
  26.  
  27. class Profile {
  28.  
  29.     var $output     = "";
  30.     var $page_title = "";
  31.     var $nav        = array();
  32.     var $html       = "";
  33.     var $parser;
  34.  
  35.     var $member     = array();
  36.     var $m_group    = array();
  37.     
  38.     var $jump_html  = "";
  39.     var $parser     = "";
  40.     
  41.     var $links      = array();
  42.     
  43.     var $bio        = "";
  44.     var $notes      = "";
  45.     var $size       = "m";
  46.     
  47.     var $lib;
  48.     
  49.     function Profile() {
  50.         global $ibforums, $DB, $std, $print;
  51.     
  52.         require "./sources/lib/post_parser.php";
  53.         
  54.         $this->parser = new post_parser();
  55.         
  56.         //--------------------------------------------
  57.         // Make sure our code number is numerical only
  58.         //--------------------------------------------
  59.         
  60.         //$ibforums->input['CODE'] = preg_replace("/^([0-9]+)$/", "$1", $ibforums->input['CODE']);
  61.         
  62.         if ($ibforums->input['CODE'] == "") $ibforums->input['CODE'] = 00;
  63.         
  64.         //--------------------------------------------
  65.         // Require the HTML and language modules
  66.         //--------------------------------------------
  67.         
  68.         $ibforums->lang = $std->load_words($ibforums->lang, 'lang_profile'  , $ibforums->lang_id );
  69.         
  70.         require "./Skin/".$ibforums->skin_id."/skin_profile.php";
  71.         $this->html = new skin_profile;
  72.         
  73.         $this->base_url        = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}?s={$ibforums->session_id}";
  74.         $this->base_url_nosess = "{$ibforums->vars['board_url']}/index.{$ibforums->vars['php_ext']}";
  75.         
  76.         //--------------------------------------------
  77.         // Check viewing permissions, etc
  78.         //--------------------------------------------
  79.         
  80.         $this->member  = $ibforums->member;
  81.         $this->m_group = $ibforums->member;
  82.         
  83.         
  84.         //--------------------------------------------
  85.         // What to do?
  86.         //--------------------------------------------
  87.         
  88.         
  89.         switch($ibforums->input['CODE']) {
  90.             case '03':
  91.                 $this->view_profile();
  92.                 break;
  93.             
  94.             //------------------------------
  95.             default:
  96.                 $this->view_profile();
  97.                 break;
  98.         }
  99.         
  100.         // If we have any HTML to print, do so...
  101.         
  102.         
  103.         $print->add_output("$this->output");
  104.         $print->do_output( array( 'TITLE' => $this->page_title, 'JS' => 1, NAV => $this->nav ) );
  105.             
  106.      }
  107.      
  108.      function view_profile() {
  109.          global $ibforums, $DB, $std, $print;
  110.          
  111.          $info = array();
  112.          
  113.          if ($ibforums->member['g_mem_info'] != 1)
  114.          {
  115.              $std->Error( array( 'LEVEL' => 1, 'MSG' => 'no_permission' ) );
  116.         }
  117.          
  118.          //--------------------------------------------
  119.         // Check input..
  120.         //--------------------------------------------
  121.         
  122.         $id = preg_replace( "/^(\d+)$/", "\\1", $ibforums->input['MID'] );
  123.         
  124.         if ( empty($id) )
  125.         {
  126.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'incorrect_use' ) );
  127.         }
  128.         
  129.         //--------------------------------------------
  130.         // Prepare Query...
  131.         //--------------------------------------------
  132.         
  133.         $DB->query("SELECT m.*, g.g_id, g.g_title as group_title FROM ibf_members m, ibf_groups g WHERE m.id='$id' and m.mgroup=g.g_id");
  134.         $member = $DB->fetch_row();
  135.         
  136.         if (empty($member['id']))
  137.         {
  138.             $std->Error( array( 'LEVEL' => 1, 'MSG' => 'incorrect_use' ) );
  139.         }
  140.         
  141.         // Play it safe
  142.         
  143.         $member['password'] = "";
  144.         
  145.         //--------------------------------------------
  146.         // Find the most posted in forum that the viewing
  147.         // member has access to by this members profile
  148.         //--------------------------------------------
  149.         
  150.         $DB->query("SELECT id, read_perms FROM ibf_forums");
  151.         
  152.         $forum_ids = array('0');
  153.         
  154.         while ( $r = $DB->fetch_row() )
  155.         {
  156.             if ($r['read_perms'] == '*')
  157.             {
  158.                 $forum_ids[] = $r['id'];
  159.             }
  160.             else if ( preg_match( "/(^|,)".$this->member['mgroup']."(,|$)/", $r['read_perms']) )
  161.             {
  162.                 $forum_ids[] = $r['id'];
  163.             }
  164.         }
  165.         
  166.         $forum_id_str = implode( ",", $forum_ids );
  167.         
  168.         $percent = 0;
  169.         
  170.         $DB->query("SELECT DISTINCT(p.forum_id), f.name, COUNT(p.author_id) as f_posts FROM ibf_posts p, ibf_forums f ".
  171.                    "WHERE p.forum_id IN ($forum_id_str) AND p.author_id='".$member['id']."' AND p.forum_id=f.id GROUP BY p.forum_id ORDER BY f_posts DESC");
  172.                    
  173.         $favourite   = $DB->fetch_row();
  174.         
  175.         $DB->query("SELECT COUNT(pid) as total_posts FROM ibf_posts WHERE author_id='".$member['id']."'");
  176.         
  177.         $total_posts = $DB->fetch_row();
  178.         
  179.         $DB->query("SELECT TOTAL_TOPICS, TOTAL_REPLIES FROM ibf_stats");
  180.         
  181.         $stats = $DB->fetch_row();
  182.         
  183.         $board_posts = $stats['TOTAL_TOPICS'] + $stats['TOTAL_REPLIES'];
  184.         
  185.         if ($total_posts['total_posts'] > 0)
  186.         {
  187.             $percent = round( $favourite['f_posts'] / $total_posts['total_posts'] * 100 );
  188.         }
  189.         
  190.         if ($member['posts'])
  191.         {
  192.             $info['posts_day'] = round( $member['posts'] / (((time() - $member['joined']) / 86400)), 1);
  193.             $info['total_pct'] = sprintf( '%.2f', ( $member['posts'] / $board_posts * 100 ) );
  194.         }
  195.         
  196.         if ($info['posts_day'] > $member['posts'])
  197.         {
  198.             $info['posts_day'] = $member['posts'];
  199.         }
  200.         
  201.         $info['posts']       = $member['posts'] ? $member['posts'] : 0;
  202.         $info['name']        = $member['name'];
  203.         $info['mid']         = $member['id'];
  204.         $info['fav_forum']   = $favourite['name'];
  205.         $info['fav_id']      = $favourite['forum_id'];
  206.         $info['fav_posts']   = $favourite['f_posts'];
  207.         $info['percent']     = $percent;
  208.         $info['group_title'] = $member['group_title'];
  209.         $info['board_posts'] = $board_posts;
  210.         $info['joined']      = $std->get_date( $member['joined'], 'LONG' );
  211.         
  212.         $info['member_title'] = $member['title']     ? $member['title']      : $ibforums->lang['no_info'];
  213.         
  214.         $info['aim_name']    = $member['aim_name']   ? $member['aim_name']   : $ibforums->lang['no_info'];
  215.         $info['icq_number']  = $member['icq_number'] ? $member['icq_number'] : $ibforums->lang['no_info'];
  216.         $info['yahoo']       = $member['yahoo']      ? $member['yahoo']      : $ibforums->lang['no_info'];
  217.         $info['location']    = $member['location']   ? $member['location']   : $ibforums->lang['no_info'];
  218.         $info['interests']   = $member['interests']  ? $member['interests']  : $ibforums->lang['no_info'];
  219.         $info['msn_name']    = $member['msnname']    ? $member['msnname']    : $ibforums->lang['no_info'];
  220.         
  221.         $ibforums->vars['time_adjust'] = $ibforums->vars['time_adjust'] == "" ? 0 : $ibforums->vars['time_adjust'];
  222.         
  223.         if ($member['dst_in_use'] == 1)
  224.         {
  225.             $member['time_offset'] += 1;
  226.         }
  227.         
  228.         $info['local_time']  = $member['time_offset'] != "" ? gmdate( "h:i A", time() + ($member['time_offset']*3600) + ($ibforums->vars['time_adjust'] * 60) ) : $ibforums->lang['no_info'];
  229.         
  230.         $info['avatar']      = $std->get_avatar( $member['avatar'] , 1, $member['avatar_size'] );
  231.         
  232.         $info['signature']   = $member['signature'];
  233.         
  234.         if ( $member['website'] and preg_match( "/^http:\/\/\S+$/", $member['website'] ) ) {
  235.             $info['homepage'] = "<a href='{$member['website']}' target='_blank'>{$member['website']}</a>";
  236.         }
  237.         else
  238.         {
  239.             $info['homepage'] = $ibforums->lang['no_info'];
  240.         }
  241.         
  242.         
  243.         if ($member['bday_month'])
  244.         {
  245.             $info['birthday'] = $member['bday_day']." ".$ibforums->lang[ 'M_'.$member['bday_month'] ]." ".$member['bday_year'];
  246.         }
  247.         else
  248.         {
  249.             $info['birthday'] = $ibforums->lang['no_info'];
  250.         }
  251.         
  252.         
  253.         if (!$member['hide_email']) {
  254.             $info['email'] = "<a href='{$this->base_url}&act=Mail&CODE=00&MID={$member['id']}'>{$ibforums->lang['click_here']}</a>";
  255.         }
  256.         else
  257.         {
  258.             $info['email'] = $ibforums->lang['private'];
  259.         }
  260.         
  261.         $info['base_url']    = $this->base_url;
  262.         
  263.         $this->output .= $this->html->show_profile( $info );
  264.         
  265.         // Is this our profile?
  266.         
  267.         if ($member['id'] == $this->member['id'])
  268.         {
  269.             $this->output = preg_replace( "/<!--MEM OPTIONS-->/e", "\$this->html->user_edit(\$info)", $this->output );
  270.         }
  271.         
  272.         // Can mods edit this profile?
  273.         
  274.         if ($ibforums->member['id'])
  275.         {
  276.             if ($ibforums->member['g_is_supmod'] == 1)
  277.             {
  278.                 $pass = 1;
  279.             }
  280.             else
  281.             {
  282.                 $DB->query("SELECT * FROM ibf_moderators WHERE edit_user=1 AND member_id='".$ibforums->member['id']."'");
  283.                 if ( $this->moderator = $DB->fetch_row() )
  284.                 {
  285.                     $pass = 1;
  286.                 }
  287.             }
  288.         }
  289.         
  290.         
  291.         
  292.          $this->page_title = $ibforums->lang['page_title'];
  293.          $this->nav        = array( $ibforums->lang['page_title'] );
  294.          
  295.      }
  296.      
  297.      
  298.      
  299. }
  300.  
  301. ?>